home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-09 | 1.9 KB | 85 lines | [TEXT/MPCC] |
- // File: PictViewer.c
- //
- // This is a piece of code which can be loaded and called by SimpleApp
-
- #include <Quickdraw.h>
- #include <Windows.h>
- #include <Files.h>
- #include <Errors.h>
- #include <Events.h>
-
- #include <FragLoad.h>
-
- // The following constants are copied from CodeFragmentTypes.r
- // They *should* be in FragLoad.h, but aren't
- enum {
- kInMem = 0,
- kOnDiskFlat,
- kOnDiskSegmented
- };
-
- // === Global variables
- PicHandle gOurPicture = NULL;
-
- // The Initialization routine has a standard calling sequence, as defined in FragLoad.h
- OSErr OurInitRoutine (InitBlockPtr initBlkPtr)
- {
- OSErr err = noErr;
- short refNum = -1;
-
- // Make sure this code is coming from the data fork of a file
- if (initBlkPtr->fragLocator.where != kOnDiskFlat) {
- err = fnfErr; // We didn't come from a file (I'd call that "file not found!" :))
- goto done;
- }
-
- refNum = FSpOpenResFile(initBlkPtr->fragLocator.u.onDisk.fileSpec,
- fsCurPerm);
- if (refNum == -1) {
- err = ResError();
- goto done;
- }
-
- UseResFile(refNum);
- gOurPicture = (PicHandle)GetIndResource('PICT', 1);
- if (gOurPicture)
- DetachResource((Handle)gOurPicture);
- else
- err = ResError();
-
- done:
- if (refNum != -1)
- CloseResFile(refNum);
- return err;
- }
-
-
- // Our main routine can have any calling sequence we want
- // This particular version is defined in SimpleApp.c
- Boolean OurMainRoutine (EventRecord *theEvent, WindowPtr currWindow, QDGlobals *qdAddress)
- {
- Boolean handled = false;
-
- if (theEvent->what == updateEvt) {
- WindowPtr theWindow = (WindowPtr)theEvent->message;
-
- BeginUpdate(theWindow);
- SetPort(theWindow);
- DrawPicture(gOurPicture, &currWindow->portRect);
- EndUpdate(theWindow);
- handled = true;
- }
-
- return handled; // Did we handle the event?
- }
-
-
- void OurTerminationRoutine()
- {
- // This will be called when this code fragment is about to be unloaded
-
- // Release the memory used for our picture
- if (gOurPicture != NULL)
- KillPicture(gOurPicture);
- }
-